#pragma once

#include "../umlmodel_global.h"

#include <memory>
#include <vector>

#include "Element.h"

using std::make_shared;
using std::shared_ptr;
using std::vector;

namespace uml {
class Classifier;
class ExecutableNode;
class ObjectNode;

/// <summary>
/// ExceptionHandler
/// An ExceptionHandler is an Element that specifies a handlerBody ExecutableNode to
/// execute in case the specified exception occurs during the execution of the
/// protected ExecutableNode.
/// </summary>
class UMLMODEL_EXPORT ExceptionHandler : public Element {

public: // Constructors and destructors
    explicit ExceptionHandler(const QString& umlType="uml::ExceptionHandler");

public: // JsonSerializable override
    void fromJson(const QJsonObject& json, QStringList& errorList) override;
    void toJson(QJsonObject& json) override;

public: // Properties
    /// <summary>
    /// exceptionInput getter
    /// An ObjectNode within the handlerBody. When the ExceptionHandler catches an
    /// exception, the exception token is placed on this ObjectNode, causing the
    /// handlerBody to execute.
    /// </summary>
    shared_ptr<ObjectNode> exceptionInput() const;

    /// <summary>
    /// exceptionInput setter
    /// An ObjectNode within the handlerBody. When the ExceptionHandler catches an
    /// exception, the exception token is placed on this ObjectNode, causing the
    /// handlerBody to execute.
    /// </summary>
    void setExceptionInput(shared_ptr<ObjectNode> value);

    /// <summary>
    /// exceptionTypes getter
    /// The Classifiers whose instances the ExceptionHandler catches as exceptions. If
    /// an exception occurs whose type is any exceptionType, the ExceptionHandler
    /// catches the exception and executes the handlerBody.
    /// </summary>
    vector<shared_ptr<Classifier>>& exceptionTypes();

    /// <summary>
    /// handlerBody getter
    /// An ExecutableNode that is executed if the ExceptionHandler catches an exception.
    /// </summary>
    shared_ptr<ExecutableNode> handlerBody() const;

    /// <summary>
    /// handlerBody setter
    /// An ExecutableNode that is executed if the ExceptionHandler catches an exception.
    /// </summary>
    void setHandlerBody(shared_ptr<ExecutableNode> value);

    /// <summary>
    /// protectedNode getter
    /// The ExecutableNode protected by the ExceptionHandler. If an exception propagates
    /// out of the protectedNode and has a type matching one of the exceptionTypes, then
    /// it is caught by this ExceptionHandler.
    /// </summary>
    shared_ptr<ExecutableNode> protectedNode() const;

    /// <summary>
    /// protectedNode setter
    /// The ExecutableNode protected by the ExceptionHandler. If an exception propagates
    /// out of the protectedNode and has a type matching one of the exceptionTypes, then
    /// it is caught by this ExceptionHandler.
    /// </summary>
    void setProtectedNode(shared_ptr<ExecutableNode> value);

private: // Fields
    /// <summary>
    /// exceptionInput
    /// An ObjectNode within the handlerBody. When the ExceptionHandler catches an
    /// exception, the exception token is placed on this ObjectNode, causing the
    /// handlerBody to execute.
    /// </summary>
    shared_ptr<ObjectNode> exceptionInput_;

    /// <summary>
    /// exceptionTypes
    /// The Classifiers whose instances the ExceptionHandler catches as exceptions. If
    /// an exception occurs whose type is any exceptionType, the ExceptionHandler
    /// catches the exception and executes the handlerBody.
    /// </summary>
    vector<shared_ptr<Classifier>> exceptionTypes_;

    /// <summary>
    /// handlerBody
    /// An ExecutableNode that is executed if the ExceptionHandler catches an exception.
    /// </summary>
    shared_ptr<ExecutableNode> handlerBody_;

    /// <summary>
    /// protectedNode
    /// The ExecutableNode protected by the ExceptionHandler. If an exception propagates
    /// out of the protectedNode and has a type matching one of the exceptionTypes, then
    /// it is caught by this ExceptionHandler.
    /// </summary>
    shared_ptr<ExecutableNode> protectedNode_;

};

} // namespace uml
